<?php
require_once '../model/AbonExamen.php';

class AbonExamenManager {
   private $bdd; // Instance de PDO
   
   function __construct($bdd) {
        $this->bdd = $bdd;
    }
    
    public function add(AbonExamen $abonExamen) {

        $q = $this->bdd->prepare('INSERT INTO ABON_EXAMEN SET idUser = :idUser, idExamen = :idExamen, libelle = :libelle');
        $q->bindValue(':idUser', $abonExamen->getIdUser());
        $q->bindValue(':idExamen', $abonExamen->getIdExamen());
        $q->bindValue(':libelle', $abonExamen->getLibelle());

        $q->execute();
        //print_r($q->errorInfo());
    }
    
    public function getListAbonExamen($id) {
        $listAbonExamen = array();
        $req = $this->bdd->prepare('SELECT * FROM ABON_EXAMEN WHERE idUser='.$id);
        $req->execute();
        while ($donnees = $req->fetch()) {
            $abonExamen = new AbonExamen($donnees["idUser"],$donnees["idExamen"],$donnees["libelle"]);
            array_push($listAbonExamen, $abonExamen);
        }
        return $listAbonExamen;
    }
    
    public function  getDate ($idExamen) {
        $requete ="SELECT EXAMENS.date FROM EXAMENS,ABON_EXAMEN WHERE EXAMENS.idExamen=ABON_EXAMEN.idExamen AND EXAMENS.idExamen=$idExamen";
        $req = $this->bdd->prepare($requete);
        $req->execute();
        $donnees = $req->fetch();
      //  var_dump($donnees);
        $date =  $donnees['date'];
        //echo ucfirst($donnees["date"]);
        return $date;
    }
    
   public function getCount ($idUser) {
        $requete ="SELECT COUNT(idExamen) FROM ABON_EXAMEN WHERE idUser=$idUser";
        $req = $this->bdd->prepare($requete);
        $req->execute();
        $donnees = $req->fetch();
        $var= $donnees[0];
        //var_dump($donnees);
        return $var;
    } 
    
    
    
}
